﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PJAA_Inventory_and_AR___Prototype
{
    public partial class Search_Client : Form
    {
        private SQLMaster master;
        private List<object[]> dataCompare = new List<object[]>();
        private Main_Menu MM;

        public Search_Client(Main_Menu MM)
        {
            InitializeComponent();
            
            
            //added this block to make the form transparent
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;

            this.MM = MM;
            master = new SQLMaster();
            dataCompare = master.loadClentList_ALL();
            LoadClientList();
        }

        private void LoadClientList()
        {
            SearchCl_DGV.Rows.Clear();
            foreach (object[] strArray in dataCompare)
            {
                if (SearchCl_Name_Txtbox.Text != string.Empty)
                {
                    if ((strArray[1] as string).ToLower().Contains(SearchCl_Name_Txtbox.Text.ToLower()))
                        //|| (strArray[2] as string).ToLower().Contains(SearchCl_Name_Txtbox.Text.ToLower()))
                    {
                        SearchCl_DGV.Rows.Add(strArray);
                    }
                }
                else
                    SearchCl_DGV.Rows.Add(strArray);

            }
        }

        public string _ClName
        {
            get { return SearchCl_DGV.SelectedCells[1].Value.ToString(); }
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.ColumnIndex == 2)
            {
                if (SearchCl_DGV.SelectedCells[0].Value==null)
                {
                    MessageBox.Show("Please select a customer first", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MM._ClientName = _ClName;
                    List_Order orderlist = new List_Order(SearchCl_DGV.SelectedCells[0].Value.ToString());
                    orderlist.TopLevel = false;
                    orderlist.Dock = DockStyle.Left;
                    panel1_searchCl.Controls.Clear();
                    panel1_searchCl.Controls.Add(orderlist);
                    //MM.Main_Panel3.Controls.Clear();
                    //MM.Main_Panel3.Visible=false;
                    //MM.Main_Panel3.Refresh();
                    orderlist.Show();
                    MM.Clientlbl.Visible = true;
                    MM.label_client.Visible = true;

                }
            }
        }

        private void textBox4_TextChanged(object sender, EventArgs e)
        {
            LoadClientList();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }



        private void label4_Click(object sender, EventArgs e)
        {

        }

        private void Search_Client_Load(object sender, EventArgs e)
        {

        }

        private void buttonClose_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void panel1_searchCl_Paint(object sender, PaintEventArgs e)
        {

        }

        private void SearchCl_EditOrder_Btn_Click(object sender, EventArgs e)
        {
            //master.addSummaryOfGoodsOnConsignment(SearchCl_DGV.SelectedCells[0].Value.ToString(),"001",1,1m);
        }
    }
}
